﻿using System;
using System.Collections.Generic;
using System.Data;
using Runda.EShop.Common.Utility;
using Runda.EShop.Dal;
using System.Data.Common;
using Runda.EShop.Common.Entity;


namespace Runda.EShop.Bll
{
    /// <summary>
    /// BLL Layer For dbo.Biz_Order.
    /// </summary>
    public partial class BizOrderBll
    {
        public void UpdateOrderStatus(Guid OrderID, EnumHelper.OrderStatus orderStatus)
        {
            BizOrderStatusEntity orderStatusEntity = new BizOrderStatusEntity();
            orderStatusEntity.OrderID = OrderID;
            orderStatusEntity.Status = (int)orderStatus;
            orderStatusEntity.StatusName = EnumDescAttribute.GetFieldText(orderStatus);
            orderStatusEntity.CreatedAt = DateTime.Now;
            orderStatusEntity.CreatedBy = Guid.Empty;
            //orderStatusEntity.CreatedByName = 
            orderStatusEntity.Deleted = false;

           base.SafeDbExecute(delegate(IDbTransaction iTran)
           {
               DbTransaction tran = iTran as DbTransaction;
               BizOrderDal dal = new BizOrderDal(tran);
               dal.Delete<BizOrderStatusEntity>(" and OrderID='"+OrderID+"' and [Status]="+((int)orderStatus).ToString());
               dal.UpdateOrderStatus(OrderID, orderStatus);

               dal.Insert(orderStatusEntity);
           });
        }
    }
}

